package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusStreetLedger;
import com.ruoyi.business.service.IBusStreetLedgerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 街道台账Controller
 * 
 * @author ling
 * @date 2024-07-11
 */
@RestController
@RequestMapping("/business/street_ledger")
public class BusStreetLedgerController extends BaseController
{
    @Autowired
    private IBusStreetLedgerService busStreetLedgerService;
    @Value("${export.max:10000}")
    private Integer max;

    /**
     * 查询街道台账列表
     */
    @PreAuthorize("@ss.hasPermi('business:street_ledger:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusStreetLedger busStreetLedger)
    {
        startPage();
        List<BusStreetLedger> list = busStreetLedgerService.selectBusStreetLedgerList(busStreetLedger);
        return getDataTable(list);
    }

    /**
     * 导出街道台账列表
     */
    @PreAuthorize("@ss.hasPermi('business:street_ledger:export')")
    @Log(title = "街道台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusStreetLedger busStreetLedger)
    {
        List<BusStreetLedger> list = busStreetLedgerService.selectBusStreetLedgerList(busStreetLedger);
        if (list.size() > max) {
            throw new ServiceException("导出失败！,每次最多导出 " + max + "条");
        }
        ExcelUtil<BusStreetLedger> util = new ExcelUtil<BusStreetLedger>(BusStreetLedger.class);
        util.exportExcel(response, list, "街道台账数据");
    }

    /**
     * 获取街道台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:street_ledger:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busStreetLedgerService.selectBusStreetLedgerById(id));
    }

    /**
     * 新增街道台账
     */
    @PreAuthorize("@ss.hasPermi('business:street_ledger:add')")
    @Log(title = "街道台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusStreetLedger busStreetLedger)
    {
        return toAjax(busStreetLedgerService.insertBusStreetLedger(busStreetLedger));
    }

    /**
     * 修改街道台账
     */
    @PreAuthorize("@ss.hasPermi('business:street_ledger:edit')")
    @Log(title = "街道台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusStreetLedger busStreetLedger)
    {
        return toAjax(busStreetLedgerService.updateBusStreetLedger(busStreetLedger));
    }

    /**
     * 删除街道台账
     */
    @PreAuthorize("@ss.hasPermi('business:street_ledger:remove')")
    @Log(title = "街道台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busStreetLedgerService.deleteBusStreetLedgerByIds(ids));
    }
}
